﻿using System;
using System.Collections.Generic;
using System.Text;

using System.Reflection;
using Little.Soldier.SWIFT.Validation;

namespace ConsoleApplication15
{
    public class ValidationRule_IsDecimal : ValidationRuleBase
    {
        public ValidationRule_IsDecimal()
        { }

        public ValidationRule_IsDecimal(string errorDescription)
            : base(errorDescription)
        { }

        public ValidationRule_IsDecimal(int startIndex)
            : base(startIndex)
        { }

        public ValidationRule_IsDecimal(int startIndex, int length)
            : base(startIndex, length)
        { }

        public ValidationRule_IsDecimal(char delimiter, int count)
            : base(delimiter, count)
        { }

        public override ValidationError[] Validate(string value)
        {
            decimal returnValue = decimal.MinValue;
            if (decimal.TryParse(value, out returnValue))
                return new ValidationError[] { };
            else
            {
                if (string.IsNullOrEmpty(ErrorDescription))
                    return new ValidationError[] { new ValidationError(ValidationErrorType.UserError, string.Format("The value '{0}' must be a decimal.", value)) };
                else
                    return new ValidationError[] { new ValidationError(ValidationErrorType.UserError, ErrorDescription) };

            }
        }
    }
}

